
import java.sql.*;
import javax.swing.JOptionPane;


public class studentStaff {
    public int staffID;
    public String loginName;
    private String password; 
    public int buildingManaging;

    private Connection connect;

    
    public studentStaff(String loginName, String password, int buildingManaging){
        this.loginName = loginName;
        this.password = password;
        this.buildingManaging = buildingManaging;
        
    }
    
    public boolean addToDB(Connection connect){
        try {
            String addQuery = "INSERT INTO DORMS.studentStaff (loginName, password,buildingManaging) "
                    + "VALUES (?,?,?)";
            PreparedStatement addStmt = connect.prepareStatement(addQuery);
            addStmt.setString(1, loginName);
            addStmt.setString(2, password);
            addStmt.setInt(3, buildingManaging);
            addStmt.execute();
            
            
            Statement stmt = connect.createStatement();
            ResultSet result = stmt.executeQuery("SELECT last_insert_id() from DORMS.studentStaff");
            if (result.next())
                staffID = result.getInt("last_insert_id()");
            return true;
            
        }catch (Exception ex){
            JOptionPane.showMessageDialog(null,
                    "Unable to add to database. Please chack for duplicates");
             
        }
        return false;
        
        
    }
   
}
